﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZK.Common
{
    /// <summary>
    /// 我的json配置对应的模型
    /// </summary>
    /// <summary>
    /// 我的json配置对应的模型
    /// </summary>
    public class Myconfig
    {
        public static MyconfigM myconfigValue = new MyconfigM();
        public class MyconfigM
        {
            /// <summary>
            /// 地磅进制
            /// </summary>
            public int DBJZ { get; set; } = 1000;
            public int DuankouhaoIndex { get; set; } = 1;
            public int BotelvIndex { get; set; } = 1;
            public int XiaoyanweiIndex { get; set; } = 1;
            public int ShujuweiIndex { get; set; } = 1;
            public int TingzhiweiIndex { get; set; } = 1;

            /// <summary>
            /// led 字体大小
            /// </summary>
            public int LEDFontSize
            {
                get; set;
            } = 9;
            /// <summary>
            /// 姓名
            /// </summary>
            public string UserName
            {
                get; set;
            }
            /// <summary>
            /// 站点名字
            /// </summary>
            public string DeptName
            {
                get; set;
            }
            /// <summary>
            /// 用户名
            /// </summary>
            public string Account
            {
                get; set;
            }
            /// <summary>
            /// 密码
            /// </summary>
            public string PassWord
            {
                get; set;
            }
            /// <summary>
            /// token
            /// </summary>
            public string Token
            {
                get; set;
            }
            /// <summary>
            /// Position
            /// </summary>
            public string Position
            {
                get; set;
            }
            /// <summary>
            /// RealPosition
            /// </summary>
            public List<string> RealPosition
            {
                get; set;
            }
            /// <summary>
            /// 磅单预览 1直接打印 2预览打印
            /// </summary>
            public string BDYL
            {
                get; set;
            }
            /// <summary>
            /// 打印机
            /// </summary>
            public string DYJ
            {
                get; set;
            }

            /// <summary>
            /// 煤泥票的打印机
            /// </summary>
            public string MNPrinter
            {
                get; set;
            }
            /// <summary>
            /// 磅单打印方式 1自动 2 手动 
            /// </summary>
            public string DYFS
            {
                get; set;
            }
            /// <summary>
            /// 上站磅单是否自动打印 1是 0否 
            /// </summary>
            public string SZSFZDDY
            {
                get; set;
            }

            /// <summary>
            /// 道闸启动方式 1车牌识别一体机 2网络继电器,默认网络继电器
            /// </summary>
            public string DZQD
            {
                get; set;
            } = "2";

            /// <summary>
            /// 境内外发货单位名称
            /// </summary>
            public string JNWFHDW
            {
                get; set;
            }

            /// <summary>
            /// 红外开关 1开 0关 
            /// </summary>
            public string HWKG
            {
                get; set;
            }

            /// <summary>
            /// 磅表进制
            /// </summary>
            public string BBJZ
            {
                get; set;
            }
            /// <summary>
            /// 继电器间隔时间 毫秒
            /// </summary>
            public int JDQJG { get; set; } = 1000;
            /// <summary>
            /// 地磅数据稳定个数
            /// </summary>
            public int DBSJWDGS { get; set; } = 5;
            /// <summary>
            /// 后端服务ip
            /// </summary>
            public string ServiceIp { get; set; } = "127.0.0.1";
            /// <summary>
            /// 后端服务端口
            /// </summary>
            public string ServicePort { get; set; } = "8080";
            /// <summary>
            /// 文件服务ip
            /// </summary>
            public string FileServiceIp { get; set; } = "127.0.0.1";
            /// <summary>
            /// 文件服务端口
            /// </summary>
            public string FileServicePort { get; set; } = "8080";
            /// <summary>
            /// 打印次数
            /// </summary>
           // public int PrintNum { get; set; } = 1;
            /// <summary>
            /// 地磅标准吨位
            /// </summary>
            public decimal DBBZ { get; set; } = 10;
            /// <summary>
            /// 煤种
            /// </summary>
            public string CoalName { get; set; } = "面煤";
            /// <summary>
            /// 入厂排队led字体大小
            /// </summary>
            public int TitleLedSize { get; set; } = 10;
            /// <summary>
            /// 排队刷新的时间（秒）
            /// </summary>
            public int PDSX { get; set; } = 60;
            /// <summary>
            /// 境外票ip
            /// </summary>
            public string CTMIP { get; set; }
            /// <summary>
            /// 境外票 端口
            /// </summary>
            public string CTMPORT { get; set; }
            /// <summary>
            /// 境外票 机器号
            /// </summary>
            public string CTMNUM { get; set; }
            /// <summary>
            /// 境外票采集ip
            /// </summary>
            public string CTMCJIP { get; set; }
            /// <summary>
            /// 境外票采集端口
            /// </summary>
            public string CTMCJPORT { get; set; }
            /// <summary>
            /// 境外票采集机器编码
            /// </summary>
            public string CTMCJNUM { get; set; }
            /// <summary>
            /// 是否推送境外煤管票 1 推 0 不推
            /// </summary>
            public string CoalManageSendW { get; set; } = "0";
            /// <summary>
            /// 是否推送境内煤管票 1 推 0 不推
            /// </summary>
            public string CoalManageSendN { get; set; } = "0";

            /// <summary>
            /// 是否打印煤泥矸石
            /// </summary>
            public string MnGsManageSend { get; set; } = "0";
            /// <summary>
            /// 是否验证煤种 1验证 0 不验证
            /// </summary>
            public string MZYZ { get; set; } = "1";

            /// <summary>
            /// 是否推送神木运销 1 推 0 不推
            /// </summary>
            public string SMYX { get; set; } = "0";
            /// <summary>
            /// 停车场id
            /// </summary>
            public string ParkingId { get; set; }
            /// <summary>
            /// 刷新文本时间，清除文本，重置LED文本
            /// </summary>
            public int RefreshTextTime { get; set; } = 5;
            /// <summary>
            /// 清除无关联卡
            /// </summary>
            public int UnRelationCardClearTime { get; set; } = 300;//5分钟清除一次
            /// <summary>
            /// 确认票号时间
            /// </summary>
            public int ConfirmTicketTime { get; set; } = 10;

            public int JnMaxLength { get; set; } = 8;
            public int JwMaxLength { get; set; } = 9;
            public int SzMaxLength { get; set; } = 9;
            public int MnGsMaxLength { get; set; } = 7;

            /// <summary>
            /// 页面数据清空时间
            /// </summary>
            public int PageDataClearTime { get; set; } = 10;

            /// <summary>
            /// 窗口编号
            /// </summary>
            public int WindowNum { get; set; } = 1;
            /// <summary>
            /// 是否自动登录
            /// </summary>
            public string IsAutoLogin { get; set; } = "0";

            /// <summary>
            /// 放行车辆定时查询
            /// </summary>
            public int FxCarListSelectTimer { get; set; } = 60;

            public string IsPreviewPrint { get; set; } = "1";//默认预览打印

            public string IsDoubleCheck { get; set; } = "1";//默认验证（卡号、车牌号双校验）

            /// <summary>
            /// 磅单打印张数
            /// </summary>
            public int PoundPrintCount { get; set; } = 1;

            /// <summary>
            /// 过磅模式  0公共，1只除皮，2只称重
            /// </summary>
            public string GBMS { get; set; } = "0";

            /// <summary>
            /// 仓下除皮语音及LED提示信息
            /// </summary>
            public string CXCPMSG { get; set; } = "除皮成功，请重新刷卡装车";

            /// <summary>
            /// 停车场有放行车辆语音提示
            /// </summary>
            public String FXTIPMSG { get; set; } = "请注意有放行车辆，请放行";

            /// <summary>
            /// 地磅误差
            /// </summary>
            public decimal DBWC { get; set; } = 0;

            /// <summary>
            /// 地磅数据稳定的个数
            /// </summary>
            public int WeightCount { get; set; } = 8;

            /// <summary>
            /// 摄像头码流模式
            /// 0主码流，1子码流
            /// </summary>
            public string VideoRate { get; set; } = "1";
            /// <summary>
            /// 运输卡前缀
            /// </summary>
            public string YSKQZ { get; set; } = "0";
            public string Port { get; set; } = "5005";
        }

        public class OracleBackUp {
            public string IP { get; set; } = "127.0.0.1";
            public string Port { get; set; } = "1521";
        }

        /// <summary>
        /// 读取配置文件并赋值
        /// </summary>
        /// <returns></returns>
        public static bool ReadMyconfigM()
        {
            try
            {
                if (!File.Exists("config.json"))
                {
                    File.Create("config.json");
                }
                string str = File.ReadAllText("config.json");
                var res = Newtonsoft.Json.JsonConvert.DeserializeObject<Myconfig.MyconfigM>(str);
                if (res != null)
                {
                    Myconfig.myconfigValue = res;
                }
                return true;
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr(ex.ToString());
                //MessageBox.Show("CAN卡配置有误！");
                return false;
            }
        }
        /// <summary>
        /// 写我的配置文件
        /// </summary>
        /// <returns></returns>
        public static bool WhriteMyconfigM()
        {
            try
            {
                if (!File.Exists("config.json"))
                {
                    File.Create("config.json");
                }
                File.WriteAllText("config.json", Newtonsoft.Json.JsonConvert.SerializeObject(Myconfig.myconfigValue));

                return true;
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr(ex.ToString());
                //MessageBox.Show("CAN卡配置有误！");
                return false;
            }
        }

    }
}
